#include "Timer.h"
Timer::Timer()
	:Component(COMP_TIMER)
{
	m_lastTime=system_clock::now();
	m_curTime=m_lastTime;
}

Timer::~Timer()
{
}

void Timer::AddedToObject()
{
	RequestMessage(MSG_TIME_INCR,&Timer::GetIncrTime);
}

void Timer::Update()
{
	m_lastTime=m_curTime;
	m_curTime=system_clock::now();
}

system_clock::time_point::duration Timer::GetMillisecondsElapsed()
{
	return m_curTime-m_lastTime;
}

int Timer::GetIncrTime()
{
	system_clock::time_point::duration tmp=m_curTime-m_lastTime;
	return  boost::chrono::duration_cast<boost::chrono::milliseconds>(tmp).count();
}

void Timer::GetIncrTime(const Message& msg)
{
	int* incr;
	AuxUnGroupArgus(msg.p,incr);
	*incr=GetIncrTime();
}